package top.blackr.folivora.common.pay.pay;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import top.blackr.folivora.common.pay.exception.PayException;
import top.blackr.folivora.common.pay.pay.entity.OrderStrResult;
import top.blackr.folivora.common.pay.pay.entity.PayCallbackLog;

import java.util.Map;

/**
 * 支付工厂
 *
 * @author BlackR
 */
@Component
@AllArgsConstructor
public class RetailerPayFactory {

    private final Map<String, IPayStrategy<? extends OrderStrResult, ?, ? extends PayCallbackLog>> payStrategyMap;

    @SuppressWarnings("unchecked")
    public <R extends IPayStrategy<? extends OrderStrResult, ?, ? extends PayCallbackLog>> R getPayStrategy(String payType) {
        if (!payStrategyMap.containsKey(payType)) {
            throw new PayException("暂不支持该支付方式，" + payType);
        }
        return (R) payStrategyMap.get(payType);
    }
}
